package com.hex.liyue.giftmodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.commonmodule.utils.DateUtils;
import com.hex.liyue.giftmodule.bean.DiscountGiftsBean;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterDiscountGifts extends RecyclerView.Adapter<AdapterDiscountGifts.MyHolder> {
    private OnItemClickListener onItemClickListener;
    private List<DiscountGiftsBean.DataBean> list;

    public void setList(List<DiscountGiftsBean.DataBean> list) {
        this.list = list;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(int position);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_discount_gifts, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        DiscountGiftsBean.DataBean dataBean = list.get(position);
        holder.rl_item_box.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClickListener(position);
            }
        });

        holder.tv_discount_date.setText("折现时间：" + DateUtils.getFormatDate(dataBean.cash_time * 1000, "yyyy-MM-dd"));
        holder.tv_discount_num.setText("提现单号：" + dataBean.user_gift_cash_id);
        holder.tv_discount_prices.setText("折现金额：￥" + dataBean.fact_cash);
        holder.tv_discount_states.setText("折现状态：已折现");
            Glide.with(LiYueApplication.getInstance())
                    .load(dataBean.gift_list.get(0).gift_url).centerCrop().error(R.drawable.no_icon)
                    .into(holder.iv_icon);
    }

    @Override
    public int getItemCount() {
       if(list==null){
           return 0;
       }
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        RelativeLayout rl_item_box;
        TextView tv_discount_date;
        TextView tv_discount_prices;
        TextView tv_discount_num;
        TextView tv_discount_states;
        ImageView iv_icon;

        public MyHolder(View itemView) {
            super(itemView);
            rl_item_box = (RelativeLayout) itemView.findViewById(R.id.rl_item_box);
            tv_discount_date = (TextView) itemView.findViewById(R.id.tv_discount_date);
            tv_discount_prices = (TextView) itemView.findViewById(R.id.tv_discount_prices);
            tv_discount_num = (TextView) itemView.findViewById(R.id.tv_discount_num);
            tv_discount_states = (TextView) itemView.findViewById(R.id.tv_discount_states);
            iv_icon = (ImageView) itemView.findViewById(R.id.iv_icon);
        }
    }
}
